//
// Created by 11510 on 2024/6/24.
//
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

template<typename Container>
void display(const Container &con) {
    for (auto &elem: con) {
        cout << elem << " ";
    }
    cout << endl;
}

void test0() {
    vector<int> number = {3, 2, 5, 8, 4, 7, 6, 9};

//    在vector尾部插入与删除
    number.push_back(100);
    number.push_back(200);
    display(number);
    number.pop_back();
    display(number);

    /**
     * vector是一端开口，头部不可删除、插入
     */

}


void test1() {
    vector<int> number = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    display(number);
    cout << "number.size() = " << number.size() << endl;//9
    cout << "number.capacity() = " << number.capacity() << endl;//9
    cout << endl << "在容器尾部进行插入: " << endl;
    number.push_back(10);
    number.push_back(11);
    display(number);
    cout << "number.size() = " << number.size() << endl;//11
    cout << "number.capacity() = " << number.capacity() << endl;//18

    cout << endl << "在容器vector中间进行插入: " << endl;
    auto it = number.begin();
    ++it;
    ++it;
    number.insert(it, 22);
    display(number);
    cout << "*it = " << *it << endl;
    cout << "number.size() = " << number.size() << endl;//12
    cout << "number.capacity() = " << number.capacity() << endl;//18


}


int main() {
    test1();
    return 0;
}